package com.gitee.fsmxm.wt.data;

import javax.websocket.Session;
import java.util.Collection;
import java.util.concurrent.ConcurrentHashMap;

public class Users {

    //<nickname, session>
    private static final ConcurrentHashMap<String, Session> users
            = new ConcurrentHashMap<>();

    public static boolean isNicknameLoggedIn(String nickname) {
        return users.containsKey(nickname);
    }

    public static void addUser(String nickname, Session session) {
        users.put(nickname, session);
    }

    public static int countUser() {
        return users.size();
    }

    public static Collection<Session> getSessions() {
        return users.values();
    }

    public static void removeUser(String nickname) {
        users.remove(nickname);
    }

    public static boolean isSameUser(String nickname, Session session) {
        return session == users.get(nickname);
    }
}
